/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wsn;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Collections;
import java.util.List;
import javax.swing.JPanel;
import network.Network;
import network.NetworkInfo;
import helper.Config;
import schedulingScheme.POI;
import schedulingScheme.SensorNode;

/**
 *
 * @author Andrzej
 */
public class SensorMap extends JPanel {
    private List<SensorNode> sensorList =  Collections.EMPTY_LIST;
    private List<POI> poiList =  Collections.EMPTY_LIST;
    private double areaSizeInMeters = Config.getX();
    private NetworkInfo networkInfo;

    public void setSensorList(List<SensorNode> sensorList) {
        this.sensorList = sensorList;
    }

    public void setPoiList(List<POI> poiList) {
        this.poiList = poiList;
    }

    public double getAreaSizeInMeters() {
        return areaSizeInMeters;
    }

    public List<POI> getPoiList() {
        return poiList;
    }

    public List<SensorNode> getSensorList() {
        return sensorList;
    }

    public void setNetworkInfo(NetworkInfo n) {
        this.networkInfo = n;
    }
    

    
    

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        

        for (SensorNode sn: sensorList){
            int x = (int) ((sn.getX() + 0.0) / areaSizeInMeters * getWidth());
            int y = (int) ((sn.getY() + 0.0) / areaSizeInMeters * getHeight());
            if (sn.isOn() && networkInfo!= null && networkInfo.getSensorRole(sn) == NetworkInfo.NOT_IN_NETWORK){
                g.setColor(Color.green);
//                g.drawString("Awaken", x + 5, y -5);
            }
            else if (sn.isOn()&& networkInfo!= null && networkInfo.getSensorRole(sn) == NetworkInfo.CLUSTER_HEAD){
                g.setColor(Color.red);
                g.drawString("CH", x + 5, y -5);
            }
            else if (sn.isOn()&& networkInfo!= null && networkInfo.getSensorRole(sn) == NetworkInfo.REGULAR_NODE){
                g.setColor(Color.red);
            }
            else if (sn.getBattery() > 0)
                g.setColor(Color.blue);
            else
                g.setColor(Color.gray);

            g.fillRect(x -1, y - 1, 3, 3);
            int r = (int)(sn.getR()/areaSizeInMeters*getWidth());
            if (sn.isOn())
                g.drawOval(x - r, y - r, r*2, r*2);
                
        }
        g.setColor(Color.black);
        for (POI p: poiList){
            int x = (int)((p.getX()+ 0.0)/areaSizeInMeters*getWidth());
            int y = (int)((p.getY()+ 0.0)/areaSizeInMeters*getHeight());
            g.drawLine(x-1, y+1, x+1, y-1);
            g.drawLine(x-1, y-1, x+1, y+1);
        }
        
//        g.setColor(Color.black);
//        for (int i = 0; i < areaSizeInMeters/Config.getPOIdistance();i= i +20){
//            int x = (int)(Config.getPOIdistance()/areaSizeInMeters *i*getWidth());
//            g.drawLine(x, 0, x, getHeight());
//            g.drawLine(0, x, getWidth(), x);
//        }




        
    }




  


}
